using UnityEngine;

public class SwipeUIController : MonoBehaviour
{
    [Header("需要闪烁的两个 2D 对象")]
    public GameObject target1;
    public GameObject target2;

    [Header("闪烁参数")]
    public float blinkDuration = 1f;         // 闪烁总时长
    public float blinkInterval = 0.2f;       // 每次闪烁间隔

    private void Start()
    {
        if (target1 != null) target1.SetActive(true);
        if (target2 != null) target2.SetActive(true);

        StartCoroutine(BlinkAndDisableSelf());
    }

    private System.Collections.IEnumerator BlinkAndDisableSelf()
    {
        float timer = 0f;
        bool visible = true;

        while (timer < blinkDuration)
        {
            visible = !visible;

            if (target1 != null) target1.SetActive(visible);
            if (target2 != null) target2.SetActive(visible);

            yield return new WaitForSeconds(blinkInterval);
            timer += blinkInterval;
        }

        // 确保最终是隐藏状态
        if (target1 != null) target1.SetActive(false);
        if (target2 != null) target2.SetActive(false);

        // 禁用当前对象
        gameObject.SetActive(false);
    }
}
